<template>
  <div class="position-vitae" v-loading="vitaes.loading">
    <el-table
      :data="vitaes.rows"
      style="width: 100%">
      <el-table-column
        prop="index"
        label="序号"
        align="center"
        type="index"
        width="60">
      </el-table-column>

      <el-table-column
        prop="username"
        label="姓名">
      </el-table-column>

      <el-table-column
        label="年龄">
        <template slot-scope="scope">
          {{getAge(scope.row.birthday)}}
        </template>
      </el-table-column>

      <el-table-column
        label="性别">
        <template slot-scope="scope">
          {{scope.row.sex === 1 ? '男' : '女'}}
        </template>
      </el-table-column>

      <el-table-column
        prop="workYear"
        label="工作经验">
      </el-table-column>

      <el-table-column
        label="学历">
        <template slot-scope="scope">
          {{getEducation(scope.row.education)}}
        </template>
      </el-table-column>

      <el-table-column
        label="投递时间"
        width="120">
        <template slot-scope="scope">
          {{$formatYMD(scope.row.ctime)}}
        </template>
      </el-table-column>
      
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="seeVitae(scope.row)">查看简历</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="list-page">
      <el-pagination
        :current-page="vitaes.pageIndex"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="vitaes.pageSize"
        class="fr"
        layout="sizes, prev, pager, next"
        :total="vitaes.count">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import PagedList from '../../libs/PagedList.js'

export default {
  name: 'positionvitae',
  title: '职位投递的记录',
  data() {
    return {
      vitaes: new PagedList('/mscs/position/findPositionResumes', 10),
      positionId: '',
      educationes: [
        {label: '博士', value: 'DOCTOR'},
        {label: '硕士', value: 'MASTER'},
        {label: '本科', value: 'BACHELOR'},
        {label: '大专', value: 'COLLEGE'},
        {label: '中技', value: 'TECHNICAL_SCHOOL'},
        {label: '中专', value: 'TECHNICAL_SECONDARY_SCHOOL'},
        {label: '高中以下', value: 'HIGH_SCHOOL'}
      ]
    }
  },
  methods: {
    // 本组件不调用，供父组件调用，需要传入职位id
    search (id) {
      this.positionId = id
      this.vitaes.search({positionId: id})
    },
    seeVitae (row) {
      if (row.applyStatus === 'NO') {
        axios.post('/mscs/resume/updateResumesStatus', this.$paramsConvert(
          {userId: row.userId, positionId: this.positionId}
        ))
      }
      const {href} = this.$router.resolve({
        name: 'vitaepreview',
        params: {id: this.$compileStr(row.snapshotId)}
      })
      window.open(href, '_blank')
    },
    getAge (birthday) {
      return new Date().getFullYear() - new Date(birthday).getFullYear()
    },
    getEducation (str) {
      for (let i = 0; i < this.educationes.length; i++) {
        if (str === this.educationes[i].value) {
          return this.educationes[i].label
        }
      }
    }
  },
 
}
</script>
